package com.itqf.quartz03;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.io.IOException;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/26
 * @Time: 上午11:38
 */
public class MyBackupDBJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //1.Runtime对象
        Runtime runtime = Runtime.getRuntime();
        //2.执行mysqldump命令
        String filename = "/Users/liliting/Desktop/java2003/_15QuartzDemo01/sql/"+System.currentTimeMillis()+".sql";
        String command = "mysqldump -uroot -padmin mydb -r "+filename;//mysql环境变量
        try {
            runtime.exec(command);

            System.out.println("备份成功。。。");

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
